package com.zbf.config;

import io.minio.MinioClient;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/6/7  19:11
 * 描述:
 */
@Configuration
public class MyConfig implements WebMvcConfigurer {

    @Autowired
    private TestMinioProperties testMinioProperties;


    @Bean
    public MinioClient getMinioClient() throws InvalidPortException, InvalidEndpointException {

        return new MinioClient(testMinioProperties.getUrl(),testMinioProperties.getUsername(),testMinioProperties.getPassword());

    }


    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedHeaders("*")
                .allowedMethods("*")
                .allowedOrigins("http://localhost:8080")
                .allowCredentials(true);
    }
}
